#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define DEBUG 0
#define NOISY_TEST 1

int check_gainCard(int supply_pos, struct gameState *post, int toFlag, int player){
// int check_updateCoins(int p, struct gameState *post, int bonus) {
  // struct gameState pre;
  // memcpy (&pre, post, sizeof(struct gameState));

  int r;
  // r = drawCard (p, post);
  
  // supply_pos = 1 or 2
  // toFlag = 1, 2 or 3
  // player = 0 or 1
  if(supply_pos == 1 && toFlag == 0 && player == 0){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 1 && toFlag == 0 && player == 1){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 1 && toFlag == 1 && player == 0){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 1 && toFlag == 1 && player == 1){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 1 && toFlag == 2 && player == 0){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 1 && toFlag == 2 && player == 1){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 2 && toFlag == 0 && player == 0){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 2 && toFlag == 0 && player == 1){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 2 && toFlag == 1 && player == 0){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 2 && toFlag == 1 && player == 1){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 2 && toFlag == 2 && player == 0){
	r = gainCard(supply_pos, post, toFlag, player);
  }else if(supply_pos == 2 && toFlag == 2 && player == 1){
	r = gainCard(supply_pos, post, toFlag, player);
  }
  
  
	// r = updateCoins(p, post, bonus);
  
  
  
  
  
/*  
  if (pre.deckCount[p] > 0) {
    pre.handCount[p]++;
    pre.hand[p][pre.handCount[p]-1] = pre.deck[p][pre.deckCount[p]-1];
    pre.deckCount[p]--;
  } else if (pre.discardCount[p] > 0) {
    memcpy(pre.deck[p], post->deck[p], sizeof(int) * pre.discardCount[p]);
    memcpy(pre.discard[p], post->discard[p], sizeof(int)*pre.discardCount[p]);
    pre.hand[p][post->handCount[p]-1] = post->hand[p][post->handCount[p]-1];
    pre.handCount[p]++;
    pre.deckCount[p] = pre.discardCount[p]-1;
    pre.discardCount[p] = 0;
  }
*/

  assert (r == 0 || r == -1);
  return 0;

  // assert(memcmp(&pre, post, sizeof(struct gameState)) == 0);
}

int main () {

  int i, n, r, p, bonus, supply_pos, toFlag, player, deckCount, discardCount, handCount;

  int k[10] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall};

  struct gameState G;

  printf ("Testing gainCard.\n");

  SelectStream(2);
  PutSeed(3);

  for (n = 0; n < 1000; n++) {
    for (i = 0; i < sizeof(struct gameState); i++) {
      ((char*)&G)[i] = floor(Random() * 256);
    }

	player = floor(Random() * 2);
	
    supply_pos = floor(Random() * 2)+1;

    G.deckCount[player] = floor(Random() * MAX_DECK);
    G.discardCount[player] = floor(Random() * MAX_DECK);
    G.handCount[player] = floor(Random() * MAX_HAND);
	
	toFlag = floor(Random() * 3);
	
    check_gainCard(supply_pos, &G, toFlag, player);
  }

  printf ("ALL TESTS OK\n");

  exit(0);

  return 0;
}
